const App = {
    mixins: [Save],//配置文件，路径/utils/mixins.js
    data() {
        return {
            category: [],
            village: [],
            member: [],
            person: [],
            city1: [],
            qwer: [],
            childDataForm1: [{}],
            is: true,

        };
    },
    mounted() {

        this.getCategory();
        this.getVillage();

        // this.getMember();




    },
    watch: {
        'dataForm.Village_Number'(val) {
            if (this.action == 'Modify' && this.is) {
                this.is = false;
                let str = this.dataForm.Village_Number
                console.log(this.dataForm);
                $.ajax({
                    headers: requestHeaders(),
                    url: `${mh}/clientOperation/getDistrictTree`,
                    type: "GET",
                    data: {
                        DistrictCode: str.substring(0, 6)
                    },
                    success: (data) => {


                        this.qwer = [str.substring(0, 9), str];


                    },
                    complete: (XMLHttpRequest) => {
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json",
                });

                let strsql = '';
                strsql = " and  RR_Village_Number ='" + str + "'";

                $.ajax({
                    headers: requestHeaders(),
                    url: `${mh}/generalBusiness/generalQueryByTableName`,
                    type: "POST",
                    data: {
                        Data: 'personal_information',
                        Condition: "Row_Status='0'" + strsql,
                    },
                    success: (res) => {
                        this.member = res;
                    },
                    complete: (XMLHttpRequest) => {
                        requestPretreatment(XMLHttpRequest);
                    },
                });

            }
        },
    },
    methods: {
         handleSubmitbyCustomer() {
            if (this.dataForm.team_name) {
                //判断巡逻队重名
                $.ajax({
                    headers: requestHeaders(),
                    url: `${mh}/generalBusiness/generalQueryByTableName`,
                    type: "POST",
                    data: {
                        Data: 'patrol_team',
                        Condition: "Row_Status='0' and team_name='" + this.dataForm.team_name + "'"
                    },
                    success: (data) => {
                        if (data.length > 0) {
                            this.$message.error("已存在此名称的巡逻队!");
                            return;
                        }
                        else {
                            this.handleSubmit();
                        }
                    },
                    complete: (XMLHttpRequest) => {
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json",
                });
            }

        },
        getCategory() {


            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'patrol_category',
                    Condition: "Row_Status='0'"
                },
                success: (data) => {
                    this.category = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
        },



        changeVillage(val) {
            let _this = this;
            let str = val[val.length - 1];
            this.dataForm.Village_Number = str;



            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'personal_information',
                    Condition: "Row_Status='0' and  RR_Village_Number ='" + str + "'",
                },
                success: (res) => {
                    this.member = res;
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
            });

            _this.dataForm.Captain_Number = '';
            _this.dataForm.Contact_Phone = '';
        },

        getVillage() {
            $.ajax({
                headers: requestHeaders(),


                url: `${mh}/permissionsTree/getDistrictTreeByPermissions`,
                type: "GET",
                data: {
                    DistrictCode: getCookie('village'),
                },
                success: (data) => {
                    this.city1 = data[0].children;
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });


        },

        handleSelectMember(val) {
            let _this = this;
            let selectedRow = _this.member.filter(m => m.ID_Card_Number === val)

            _this.dataForm.Contact_Phone = selectedRow[0].Contact_Phone;

        }

    },
};
const { createApp, ref } = Vue;
const app = createApp(App);
app.use(ElementPlus, { locale: zhCn });
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
app.component('yl-upload', ylUpload);
app.component('yl-select', ylSelect);
app.component('yl-text-editor', ylTextEditor);
const ElMessage = ElementPlus.ElMessage;
app.mount("#app");
